package com.base.monitor.model.model.biz.cfg.entity;

import com.base.monitor.model.model.biz.cfg.vo.IndicatorCommandVo;
import com.base.monitor.model.model.biz.cfg.vo.IndicatorDeviceGatewayVo;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.*;

/**
 * @description:
 * @author: tsing
 * @create: 2021-06-17 22:18
 */
@Data
@NoArgsConstructor
public class Gateway {

    @JsonFormat(shape = JsonFormat.Shape.STRING)
    private Long gatewayId; // 网关id
    private String gatewayIp;
    private String gatewayName;
    private String command; // 连接命令
    private Integer gatewayType; // 网关类型，1连线，2 4g
    private Integer count; // 指标数量
    private List<IndicatorCommandVo> indicators;
    @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss", locale="zh", timezone="GMT+8")
    private Date onlineTime; // 在线时间
    private Integer status; // 在线状态，0离线，1在线
    private Boolean needSend; // 是否需要发送定时命令
    private String version; // 版本

    public Gateway(IndicatorDeviceGatewayVo vo) {
        this.gatewayId = vo.getGatewayId();
        this.gatewayType = vo.getGatewayType();
        if (this.gatewayType == 1) {
            this.gatewayIp = vo.getGatewayIp();
        }
        this.gatewayName = vo.getGatewayName();
        this.command = vo.getConnectMessage();
        this.indicators = new ArrayList<>();
    }

    @Override
    public boolean equals(Object obj) {
        if (!(obj instanceof Gateway)) {
            return false;
        }
        Gateway tmp = (Gateway) obj;
        return tmp.getGatewayId().equals(this.gatewayId);
    }

}
